﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.Linq.Expressions;
using MI.ORM.IDAL;

namespace MI.ORM.Repository
{

    public class Repository<T> : IRepository<T> where T : class
    {
        private IDatabase _database;
        public Repository(IDatabase dabatase)
        {
            _database = dabatase;
        }

        public T FindBy(Expression<Func<T, bool>> expression)
        {
            return _database.FilterBy(expression).SingleOrDefault();
        }

        public void Add(T entity)
        {
            _database.Add(entity);
        }

        public void Update(T entity)
        {
            _database.Update(entity);
        }

        public void Delete(T entity)
        {
            _database.Delete(entity);
        }

        public void Delete(IEnumerable<T> entities)
        {

        }

        public IQueryable<T> All()
        {
            return _database.All<T>();
        }
        
    }

}
